package com.newcoder.leetcode;

import java.util.Arrays;

public class 合并两个有序数组 {

    public static void main(String[] args) {
        int[] nums1 = new int[]{1,2,3,0,0,0};
        int[] nums2 = new int[]{2,5,6};
        merge(nums1, 3, nums2, 3);
    }

    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] mergeArr = new int[m+n];
        if(nums1.length>0){
            for (int i = 0; i < nums1.length; i++) {
                mergeArr[i]=nums1[i];
            }
        }

        if(nums2.length>0){
            for (int i = 0; i < nums2.length; i++) {
                mergeArr[i+m]=nums2[i];
            }
        }

        Arrays.sort(mergeArr);
        for (int i = 0; i < nums1.length; i++) {
            nums1[i]=mergeArr[i];
        }
        System.out.println(Arrays.toString(nums1));
    }

}
